package com.xhl.oauth2.config.jwt;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;


@Configuration
//@ConfigurationProperties(prefix = "jwt.token")
public class MyJwtTokenConfig {
    @Value("${jwt.token.signingKey}")
    private String signingKey;

    @Bean
    public TokenStore jwtTokenStore(){
        return new JwtTokenStore(jwtAccessTokenConverter());
    }

    //使用Jwt来作为token的生成，能获取全部的信息
    //用来配置令牌端点(Token Endpoint)的安全约束
    //使用我们的凭证来作为token的生成规则
    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter(){
        JwtAccessTokenConverter accessTokenConverter = new JwtAccessTokenConverter();

        accessTokenConverter.setSigningKey(signingKey);
        return accessTokenConverter;
    }

    //Jwt内容增强器的配置类,定义新增的校验内容
    @Bean
    public TokenEnhancer jwtTokenEnhancer(){
        return new MyJwtTokenEnhancer();
    }
}
